/*--------------------劳务模块.劳务公司管理--ly-----------------*/
/*---------------------劳务公司信息修改功能  lb_company_edit.html------------------*/


$(document).ready(function() {
	//获取cookie:ueserid & Wtid
	var projectid = $.cookie("projectid");
	var editcookie = $.cookie("nav");
	var Wtid = JSON.parse(editcookie).w;

	//填充数据
	var searchurl = dataport + '/EquipmentController/selectById'; //查询
	$.post(searchurl, {
		'projectid': projectid,
	}, function(result) {
		console.log(projectid);
		var code = result.code;
		var editlist = result.object;
		if(code == 0) {
			$("#L_name").val(editlist.name); //设备名称
			$("#L_type").val(editlist.type); //设备类型
			$("#L_qrcode").val(editlist.qrcode); //二维码
			$("#L_property").val(editlist.property); //所有权
			$("#L_manager").val(editlist.manager); //管理人
			$("#L_operator").val(editlist.operator); //操作员
			$("#L_produceddate").val(editlist.produceddate); //生产日期
			$("#L_leavefactorydate").val(editlist.leavefactorydate); //出厂日期
			$("#L_picture").val(editlist.picture); //图片
			$("#L_position").val(editlist.position); //定位
		} else {
			console.log("网络不佳，稍后再试！")
		}
	});

	//layui
	layui.use(['form', 'layer'], function() {
		$ = layui.jquery;
		var form = layui.form,
			layer = layui.layer;

		//自定义验证规则
		form.verify({
			username: function(value) {
				if(value.length < 3) {
					return '昵称至少得5个字符啊';
				}
			},
		});

		//获取表单数据
		$("input").blur(function() {
			//失去焦点事件
			var name = $("#L_name").val(); //设备名称
			var type = $("#L_type").val(); //设备类型
			var qrcode = $("#L_qrcode").val(); //二维码
			var property = $("#L_property").val(); //所有权
			var manager = $("#L_manager").val(); //管理人
			var operator = $("#L_operator").val(); //操作员
			var produceddate = $("#L_produceddate").val(); //生产日期
			var leavefactorydate = $("#L_leavefactorydate").val(); //出厂日期
			var picture = $("#L_picture").val(); //图片
			var position = $("#L_position").val(); //定位
			//监听提交
			form.on('submit(edit)', function(){
				//递交修改
				editData(name,type,qrcode,property,manager,operator,produceddate,leavefactorydate,picture,position);
				return false;
			});
		});

		//修改用户信息
		var editurl = dataport + '/EquipmentController/update'; //修改
		// 获得frame索引
		var index = parent.layer.getFrameIndex(window.name);
		var editData = function(name,type,qrcode,property,manager,operator,produceddate,leavefactorydate,picture,position) {
			//修改 edit
			$.post(editurl, {
				equipid: projectid,
				name: name,
				type: type,
				qrcode: qrcode,
				property: property,
				manager: manager,
				operator: operator,
				produceddate: produceddate,
				leavefactorydate: leavefactorydate,
				picture: picture,
				position: position,
			}, function(result) {
				var code = result.code;
				if(code == 0) {
					layer.msg('修改成功!', {
						icon: 1,
						time: 1000
					}, function() {
						//关闭当前frame
						parent.layer.close(index);
					});
				} else {
					layer.msg('网络开小差了，请稍后再试!', {
						icon: 2,
						time: 1000
					}, function() {
						//关闭当前frame
//						parent.layer.close(index);
					});
				}
			})
		}

	});
})